package com.mybatis.controller.shop;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mybatis.basic.entity.AjaxJson;
import com.mybatis.basic.entity.EasyuiList;
import com.mybatis.entity.Course;
import com.mybatis.service.shop.CourseService;

/**
 * 教程
 * @author 82770
 *
 */
@Controller
@RequestMapping("/course")
public class CourseController {

	@Resource
	private CourseService courseService;

	//功能主页面
	@RequestMapping("/page")
	public String menuPage(Model model){
		return "course/list";
	}

	//教程分页数据
	@RequestMapping("/pageList")
	@ResponseBody
	public EasyuiList<Course> coursePageList(Course course,Integer page,Integer rows){
		return courseService.coursePageList(course, 0, 2);
	}

	//新增
	@RequestMapping(value = "/manage",method = RequestMethod.POST)
	@ResponseBody
	public AjaxJson add(Course course,int picId){
		return courseService.addCourse(course,picId);
	}

	//修改页面
	@RequestMapping(value = "/editPage/{id}", method = RequestMethod.GET)
	public String updatePage(@PathVariable(value = "id") int id,Model model){
		model.addAttribute("m",courseService.selectCourseById(id).getObj());
		return "course/edit";
	}

	//修改
	@RequestMapping(value = "/manage",method = RequestMethod.PUT)
	@ResponseBody
	public AjaxJson update(Course course){
		return courseService.updateCourse(course);
	}

	//删除
	@RequestMapping(value = "/manage/{id}",method = RequestMethod.DELETE)
	@ResponseBody
	public AjaxJson del(@PathVariable(value = "id")int id){
		return courseService.delCourse(id);
	}
}
